package com.hhp.hhptt.controller.controllerjinpeng;

import com.hhp.hhptt.common.Result;
import com.hhp.hhptt.entity.ImagesEntity;
import com.hhp.hhptt.entity.TVideo;
import com.hhp.hhptt.mapper.TTvideoMapper;
import com.hhp.hhptt.vo.ImagesVo;
import com.hhp.hhptt.vo.TVideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/find")
public class XiGongShangIcon {
    @Autowired
    TTvideoMapper tTvideoMapper;
//    @GetMapping("/icon")
//    public String IconInformation(@RequestParam String iconName) throws ParseException {
//            String iconUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
//                    .path("/icon/")
//                    .path(iconName)
//                    .toUriString();
//        return iconUrl;
//    }


//    @GetMapping("/images")
//    public String ImagesInformation(@RequestParam String pictureName) throws ParseException {
//        String pictureUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
//                .path("/images/")
//                .path(pictureName)
//                .toUriString();
//        return pictureUrl;
//    }
    @GetMapping("/video")
    public Result GetVideoInformation() throws ParseException {
        ArrayList<TVideoVo> objects = new ArrayList<>();
        List<TVideo> tVideos = tTvideoMapper.selectList(null);
        tVideos.stream().forEach(t->{
            TVideoVo tVideoVo = new TVideoVo();
            tVideoVo.setId(t.getId());

            String videoUrl = ServletUriComponentsBuilder.fromCurrentContextPath()
                    .path("/find/")
                    .path(t.getVideoURL())
                    .toUriString();
            tVideoVo.setVideoURL(videoUrl);
            tVideoVo.setTitle(t.getTitle());
            objects.add(tVideoVo);
        });
        return Result.success("请求成功",objects);
    }
}
